import 'dart:convert' show json;

import 'package:fluro/fluro.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

export 'package:fluro/fluro.dart';
export 'package:shared_preferences/shared_preferences.dart';

class Application {
  static Router router;

  static String jsonEncode(Object value) {
    return json.encode(value);
  }

  static dynamic jsonDecode(Object value) {
    return json.decode(value);
  }

  static Future<bool> containsKey(String key) async {
    var shared = await SharedPreferences.getInstance();
    shared.containsKey(key);
  }

  static setString(String key, String value) async {
    var shared = await SharedPreferences.getInstance();
    shared.setString(key, value);
  }

  static setBool(String key, bool value) async {
    var shared = await SharedPreferences.getInstance();
    shared.setBool(key, value);
  }

  static setDouble(String key, double value) async {
    var shared = await SharedPreferences.getInstance();
    shared.setDouble(key, value);
  }

  static setInt(String key, int value) async {
    var shared = await SharedPreferences.getInstance();
    shared.setInt(key, value);
  }

  static setStringList(String key, List<String> value) async {
    var shared = await SharedPreferences.getInstance();
    shared.setStringList(key, value);
  }

  static Future<dynamic> get(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.get(key);
  }

  static Future<String> getString(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getString(key);
  }

  static Future<bool> getBool(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getBool(key);
  }

  static Future<double> getDouble(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getDouble(key);
  }

  static Future<int> getInt(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getInt(key);
  }

  static Future<Set<String>> getKeys(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getKeys();
  }

  static Future<List<String>> getStringList(String key) async {
    var shared = await SharedPreferences.getInstance();
    return shared.getStringList(key);
  }

  static mAlertDialog(BuildContext context, String content) {
    showDialog(
      context: context,
      barrierDismissible: true, // user must tap button!
      builder: (BuildContext context) {
        return AlertDialog(
          title: Text('系统提示'),
          content: Text(content),
          actions: <Widget>[
            FlatButton(
              child: Text('确定'),
              onPressed: () {
                Navigator.of(context).pop();
              },
            ),
          ],
          elevation: 20,
          // 设置成 圆角
          shape:
              RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
        );
      },
    );
  }
}
